package com.stock.mybatisplus.handlers;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyBatisPlusHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        this.strictInsertFill(metaObject, "createDate", LocalDateTime::now, LocalDateTime.class);
//        this.strictInsertFill(metaObject, "createBy", StpUtil::getLoginId, Object.class);
//        this.strictInsertFill(metaObject, "status", () -> GlobalConstant.NORMAL, Object.class);

        this.setFieldValByName("createDate", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateDate", LocalDateTime.now(), metaObject);
//        log.info("-------{}", StpUtil.getLoginId());
//        this.setFieldValByName("createBy", StpUtil.getLoginId(), metaObject);
        this.setFieldValByName("createBy", 7L, metaObject);
//        this.setFieldValByName("status", GlobalConstant.NORMAL, metaObject);
        this.setFieldValByName("status", 0, metaObject);


    }

    @Override
    public void updateFill(MetaObject metaObject) {

//        this.strictUpdateFill(metaObject, "updateDate", LocalDateTime::now, LocalDateTime.class); // 起始版本 3.3.3(推荐)
//        this.strictInsertFill(metaObject, "updateBy", StpUtil::getLoginId, Object.class);
        this.setFieldValByName("updateDate", LocalDateTime.now(), metaObject);
//        this.setFieldValByName("updateBy", StpUtil.getLoginId(), metaObject);

    }
}
